<template>
  <div class="content-block block---3">
    <div class="info-head">{{ title }}</div>
    <div class="info-content">
      <v-chart
        ref="chart"
        :option="chartOption" style="width:100%;height:360px;"
        :theme="chartTheme" autoresize
      ></v-chart>
    </div>
  </div>
</template>

<script>
import MixinVchartTheme from '@/mixins/mixin-vchart-theme';
import BarClickListener from '@/mixins/bar-click-listener'

export default {
  name: 'grid-item-three',
  mixins: [MixinVchartTheme, BarClickListener],
  props: ['title'],
  data () {
    return {
      barClickHandlerKey: 'industryCode',
    }
  },
  computed: {
    energyIndustry () {
      return this.$store.state.energyIndustry
    },
    chartOption () {
      return {
        legend: {
          left: 'center',
        },
        grid: {
          left: '5%',
          right: '5%',
          bottom: '6%'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          }
        },
        xAxis: {
          type: 'category',
          data: this.energyIndustry.map(v => v.name),
        },
        yAxis: [
          {
            type: 'value',
            name: '吨标准煤',
            axisLine: {
              show: true
            },
            position: 'left'
          },
          {
            type: 'value',
            name: '千克标准煤/万元',
            axisLine: {
              show: true
            },
            position: 'right'
          },
        ],
        series: [
          {
            type: 'bar',
            name: '综合能源消费量',
            yAxisIndex: 0,
            data: this.energyIndustry.map((v) => ({
              name: v.name,
              code: v.code,
              value: Math.round(Math.random() * 99 + 1),
            }))
          },
          {
            type: 'bar',
            name: '产值单耗',
            yAxisIndex: 1,
            data: this.energyIndustry.map((v) => ({
              name: v.name,
              code: v.code,
              value: Math.round(Math.random() * 99 + 1),
            }))
          }
        ]
      }
    }
  },
  mounted () {
    this.$store.dispatch('GET_ENERGY_INDUSTRY')
  },
}
</script>

<style scoped>

</style>
